package main

import (
	"fmt"
	"net"
)

func main() {
	listen,err:=net.ListenUDP("udp",&net.UDPAddr{
		IP: net.IPv4(0,0,0,0),
		Port: 30000,
	})
	if err != nil {
		fmt.Println(err);return
	}
	defer func(listen *net.UDPConn) {
		err := listen.Close()
		if err != nil {

		}
	}(listen)
	for{
		var data [1024]byte
		n,addr,err:=listen.ReadFromUDP(data[:])
		if err != nil {
			fmt.Println(err);continue
		}
		fmt.Printf("data:%v addr:%v count:%v\n",string(data[:n]),addr,n)
		_, err = listen.WriteToUDP(data[:n], addr)
		if err != nil {
			fmt.Println(err)
			continue
		}
	}
}
